package cc.lj.internal.payment.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.payment.domain.pay.repository.IPayFormListRepository;
import cc.lj.internal.payment.infrastructure.dao.IPayFormListMapper;
import cc.lj.internal.payment.infrastructure.exception.PaymentExceptionEnum;
import cc.lj.internal.payment.infrastructure.po.PayformListPO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 合同收款表　mysql仓储实现
 * @author liangxifeng
 * @date 2022-01-12
 */
@Repository("payFormListMysqlRespository")
public class PayFormListMysqlRespository implements IPayFormListRepository,BasePageHelper<PayformListPO> {
    @Autowired
    private IPayFormListMapper mapper;
    @Override
    public List list(PayformListPO entityPO) {
        QueryWrapper<PayformListPO> wrapper = new QueryWrapper<>(entityPO);
        List<PayformListPO> entitys = mapper.selectList(wrapper);
        return entitys;
    }

    @Override
    public Integer updateById(PayformListPO entityPO) {
        Integer res = mapper.updateById(entityPO);
        if (res != 1)
        {
            throw new ServiceException(PaymentExceptionEnum.UPDATE_PRODUCT_CONUME_FAILED);
        }
        return res;
    }


    @Override
    public List<PayformListPO> getList(PayformListPO entityPO) {
        return this.list(entityPO);
    }

    @Override
    public Integer insert(PayformListPO entityPO) {
        Integer rows = mapper.insert(entityPO);
        if(rows != 1) {
            throw new ServiceException(PaymentExceptionEnum.INSERT_PRODUCT_CONUME_FAILED);
        }
        return entityPO.getPayformId();
    }

}
